package cn.topevery.garden.wapi.controller;

import cn.topevery.garden.dal.logic.ProjSituationRecordLogic;
import cn.topevery.garden.entity.dto.ProjSituationRecordDTO;
import cn.topevery.garden.entity.query.ProjSituationRecordQuery;
import cn.topevery.garden.entity.vo.ProjSituationRecordVO;
import cn.topevery.garden.framework.util.CurrentUserUtil;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.util.ExcelUtil;
import hw.topevery.framework.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 项目前期情况记录表
 *
 * @author code-generate
 * @date 2022-11-02
 */
@Api(tags = "工程项目-项目前期情况记录表")
@RestController
@RequestMapping("/projSituationRecord")
public class ProjSituationRecordController extends BaseController {

    @Autowired
    ProjSituationRecordLogic projSituationRecordLogic;

    /**
     * 新增/编辑 项目前期情况记录表信息
     *
     * @param dto
     * @return
     */
    @ApiOperation("新增/编辑 项目前期情况记录表信息")
    @PostMapping("/saveOrUpdate")
    public JsonResult<Boolean> saveOrUpdate(@Valid @RequestBody ProjSituationRecordDTO dto) {
        projSituationRecordLogic.insertOrUpdate(getUser().userId, dto);
        return JsonResult.ok(true);
    }

    /**
     * 根据projId获取详情
     *
     * @param projId
     * @return
     */
    @ApiOperation("根据projId获取详情")
    @GetMapping("/getByProjId")
    public JsonResult<ProjSituationRecordVO> getByProjId(@RequestParam(value = "projId") String projId) {
        return JsonResult.ok(projSituationRecordLogic.getByProjId(projId));
    }


    /**
     * 获取项目前期情况记录表分页列表
     *
     * @param query
     * @return
     */
    @ApiOperation(value = "获取项目前期情况记录表页列表")
    @GetMapping("/listPage")
    public JsonResult<DataPager<ProjSituationRecordVO>> listPage(ProjSituationRecordQuery query) {
        return JsonResult.ok(projSituationRecordLogic.listPage(query));
    }

    @ApiOperation("根据自增ID批量删除")
    @PostMapping("/deleteBatchById")
    public JsonResult<Boolean> deleteBatchById(@RequestBody Integer[] ids) {
        return JsonResult.ok(projSituationRecordLogic.deleteBatchById(ids));
    }

    @ApiOperation("导出项目前期情况记录表信息")
    @GetMapping("/export")
    public void export(ProjSituationRecordQuery query, HttpServletResponse response) {
        List<ProjSituationRecordVO> list = projSituationRecordLogic.listPage(query).records;
        ExcelUtil.exportExcel(list, "项目前期情况记录表", "sheet1", ProjSituationRecordVO.class, "项目前期情况记录表", response);
    }


}
